<template>
  <div class="playground-container">
    <div class="playground-header">
      <div class="playground-header-title" v-if="params">{{params.title}}</div>
    </div>
    <div class="playground-body" v-if="content">
      <div class="playground-body-type">{{currentContent.type}}</div>
      <div class="playground-body-number">
        <span class="playground-body-number-digit">{{currentContent.idx}}</span>
        <span class="playground-body-number-sharp">#</span>
      </div>
      <div class="playground-body-content">
        <single-chose-view
          v-if="currentContent.type==='单选题'"
          :content="currentContent"
          :valued="setAnswer"
        />
      </div>
    </div>
    <div class="playground-footer">
      <b-row>
        <b-col>
          <b-button class="playground-control-button">Indicator</b-button>
        </b-col>
        <b-col>
          <b-button class="playground-control-button">Prev</b-button>
        </b-col>
        <b-col>
          <b-button class="playground-control-button">Next</b-button>
        </b-col>
      </b-row>
    </div>
  </div>
</template>

<script>
import singleChoseView from "./subviews/singleChoseView";
export default {
  components: {
    singleChoseView
  },
  data() {
    return {
      pointer: 0,
      answerList: [
        {
          value: {
            init: "",
            final: "",
            right: ""
          },
          valid: {
            init: 0,
            final: 0
          }
        }
      ],
      content: null
    };
  },
  computed: {
    params() {
      if (this.$route.params) return this.$route.params;
      else return false;
    },
    currentContent() {
      if (this.content) return this.content[this.pointer];
      else return null;
    },
    accuracy() {
      return null;
    },
    currentStatus() {
      return null;
    }
  },
  methods: {
    setAnswer(answer) {
      let currentAnser = this.answerList[this.pointer];
      if (currentAnser.valid.init === 0) {
        currentAnser.value.init = answer.value;
        currentAnser.valid.init = answer.valid;
        currentAnser.value.right = answer.right;
      }
      currentAnser.value.final = answer.value;
      currentAnser.valid.final = answer.value;
    },
    movePointer(forward) {
      if (forward) {
        if (this.pointer < this.content.length - 1) {
          this.pointer++;
        } else {
          this.pointer = 0;
        }
      } else {
        if (this.pointer < 1) {
          this.pointer = this.content.length - 1;
        } else {
          this.pointer--;
        }
      }
    },
    initData() {
      window.console.log('initData');
      let answerSimple = this.answerList[0];
      for (let i = 1; i < this.content.length; i++) {
        this.answerList.push(answerSimple);
      }
    }
  },
  mounted() {
    if (this.params) {this.initData();}
    window.console.log(this.params);
  }
};
</script>

<style scoped>
.playground-container {
  position: fixed;
  background-color: rgb(100, 200, 100);
  top: 0px;
  left: 0px;
  right: 0px;
  bottom: 0px;
}
.playground-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 4em;
  padding: 0.5em 0 0 2em;
  display: flex;
  /* justify-content: center; */
  align-items: center;
  color: rgba(255, 255, 255, 0.9);
}
.playground-body {
  position: fixed;
  top: 4em;
  bottom: 4em;
  left: 1.5em;
  right: 1.5em;
  border-radius: 1em;
  background-color: #eee;
  box-shadow: 0 0 0.5em rgba(0, 0, 0, 0.25);
  padding: 3em 1.25em 0.25em 1.25em;
}
.playground-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4em;
  padding: 0 1em 0.5em 1em;
  display: flex;
  justify-content: center;
  align-items: center;
}
.playground-header-title {
  font-size: 2em;
}
.playground-body-type {
  position: fixed;
  top: 4em;
  right: 1.5em;
  height: auto;
  width: auto;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 0 1em 0 1em;
  padding: 0.25em 1.5em;
  color: #eee;
}
.playground-body-number {
  position: fixed;
  top: 4.25em;
  left: 2.5em;
  transition: color 0.5s ease;
  color: rgb(96, 192, 128);
  display: flex;
  align-items: flex-start;
}
.playground-body-number-digit {
  font-size: 2.25em;
}
.playground-body-number-sharp {
  font-size: 1.5em;
}
.playground-body-content {
  /* border: rgba(0, 0, 0, 0.25) 1px solid; */
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: 0.5em;
  padding-bottom: 2.5em;
}
.playground-control-button {
  outline: none;
  /* float: right; */
  border: none;
  border-bottom: 2px solid rgba(255, 255, 255, 0.6);
  color: rgba(255, 255, 255, 0.8);
  background: none;
  padding: 0.25em 0.5em 0.1em 0.5em;
  margin: 0 1em;
  border-radius: 0;
}
.playground-control-button:hover {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 1);
  border-bottom: 2px solid rgba(255, 255, 255, 1);
  transition: color 1s ease;
  transition: border-color 1s ease;
}
</style>